package liang.jiaxin.com.controller;

import liang.jiaxin.com.dto.ResponseEntity;
import liang.jiaxin.com.dto.Result;
import liang.jiaxin.com.dto.request.customer.CustomerRequestDTO;
import liang.jiaxin.com.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.http.MediaType;
import liang.jiaxin.com.service.CustomerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;


/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author Jrxsr
 * @since 2019-04-13
 */
@RestController
@RequestMapping("/api/customer")
@Api(value = "接口", description = "接口")
public class CustomerController  {

	@Autowired
	CustomerService customerService;

	@GetMapping(value = "/{id}")
	@ApiOperation(value = "详情", produces = MediaType.APPLICATION_JSON_VALUE)
	public Object get(@PathVariable("id") Long id) {
        return id;
	}

	@PostMapping(value = "/login")
	@ApiOperation(value = "登陆", produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity login(@Valid @RequestBody CustomerRequestDTO requestDTO) {
		return Result.warsucceRes(customerService.login(requestDTO));
	}

	@PostMapping(value = "/create")
	@ApiOperation(value = "注册", produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity create(@Valid @RequestBody CustomerRequestDTO requestDTO) {
		return Result.warsucceRes(customerService.create(requestDTO));
	}
}